package com.itheima.homework9;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

/*
	2. Map ：练习 Map集合的遍历方式
 */
public class Test2 {
    public static void main(String[] args) {
        HashMap<Character, Integer> hs = new HashMap<>();
        System.out.println("请输入一个字符串：");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入数据：");
        String line = sc.nextLine();
        char[] array = line.toCharArray();
        for (int i = 0; i < array.length; i++) {
            char c = array[i];
            if (hs.containsKey(c)) {
                int count = 0;
                count = hs.get(c);
                count++;
                hs.put(c, count);


            } else {
                hs.put(c, 1);
            }


        }
        System.out.println("-----1.keySet-----");
        Set<Character> keys = hs.keySet();
        for (Character key : keys) {
           int value=hs.get(key);
            System.out.println(key + "---" + value);
        }
        System.out.println("-----2.entrySet------");
        Set<Map.Entry<Character, Integer>> entries = hs.entrySet();
        for (Map.Entry<Character, Integer> entry : entries) {
            Character key=entry.getKey();
            Integer value=entry.getValue();
            System.out.println(key + "---" + value);
        }
        System.out.println("----3.lambda------");
        hs.forEach((key, value) -> System.out.println(key + "---" + value));
    }
}
